local hx__tuiying = fk.CreateSkill {

  name = "hx__tuiying",

  tags = { Skill.Limited, },

}

local hx_jianshen__getjianqi = function (room, player, num)
  local maxnum
  if player:usedSkillTimes("hx__tuiying",Player.HistoryGame) == 0 then
    maxnum = 3 - player:getMark("@hx__jianqi")
  else
    maxnum = 5 - player:getMark("@hx__jianqi")
  end
   local getnum = math.min(maxnum,num)
   room:addPlayerMark(player,"@hx__jianqi",getnum)
end

hx__tuiying:addEffect(fk.EnterDying, {
  name = "hx__tuiying",
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(hx__tuiying.name) and target and target == player and player:usedSkillTimes(hx__tuiying.name,Player.HistoryGame) == 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player.general == "hxqunyou__jianshenwuming" then
      room:setPlayerProperty(player,"general","hxqunyou__jianshenwuming_juexing")
    end
    room:recover{
      who = player,
      num = 3,
      recoverBy = player,
      skillName = hx__tuiying.name,
    }
    hx_jianshen__getjianqi(room,player,4)
    room:setPlayerMark(player,"@hx__tuiying","hx__tuiying_wudi")
    room:handleAddLoseSkills(player,"hx__guizhong|hx__wanjian")
  end,
})

hx__tuiying:addEffect(fk.DamageInflicted, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(hx__tuiying.name) and target and target == player and player:getMark("@hx__tuiying") == "hx__tuiying_wudi"
  end,
  on_refresh = function (self, event, target, player, data)
      data:preventDamage()
  end
})
hx__tuiying:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(hx__tuiying.name) and target and target == player and player:getMark("@hx__tuiying") == "hx__tuiying_wudi"
  end,
  on_refresh = function (self, event, target, player, data)
      player.room:setPlayerMark(player,"@hx__tuiying",0)
  end
})

return hx__tuiying